package tests;

import gameComponents.Player;
import gamePieces.Bishop;


import java.awt.Point;
import java.util.ArrayList;

import junit.framework.TestCase;

/**
 * 
 */

/**
 * @author SELMAN
 *
 */
public class BishopTest extends TestCase {

	Player p = new Player(1);
	Bishop b = new Bishop(0,0,p);
	/**
	 * @param name
	 */
	public BishopTest(String name) {
		super(name);
	}

	/* (non-Javadoc)
	 * @see junit.framework.TestCase#setUp()
	 */
	protected void setUp() throws Exception {
		super.setUp();
	}

	/* (non-Javadoc)
	 * @see junit.framework.TestCase#tearDown()
	 */
	protected void tearDown() throws Exception {
		super.tearDown();
	}

	/**
	 * Test method for {@link Bishop#checkIfLegal(int, int)}.
	 * @author Selman Selman
	 */
	public final void testCheckIfLegal() {
		//check if checkIfLegal would return true if bishop moves diagonally
		assertTrue(b.checkIfLegal(1,1));
		//check if checkIfLegal would return false if bishop did not move in L shape
		assertFalse(b.checkIfLegal(1, 3));
		//check if checkIfLegal would return false if bishop was trying to move out of boundaries
		assertFalse(b.checkIfLegal(9, 9));	
		}

	/**
	 * Test method for {@link Piece#getX()}.
	 * @author Selman Selman
	 */
	public final void testGetX() {
		//since Bishop is created initially at (0,0)
		//getX() should return 0
		assertEquals(b.getX(),0);
	}

	/**
	 * Test method for {@link Piece#getY()}.
	 * @author Selman Selman
	 */
	public final void testGetY() {
		//since bishop is created initially at (0,0)
		//getY() should return 0
		assertEquals(b.getY(),0);
	}

	/**
	 * Test method for {@link Piece#setX(int)}.
	 * @author Selman Selman
	 */
	public final void testSetX() {
		b.setX(1); // set x coordinate to 1
		//check that x is now 1
		assertEquals(b.getX(),1);
	}

	/**
	 * Test method for {@link Piece#getOwnership()}.
	 * @author Selman Selman
	 */
	public final void testGetOwnership() {
		//get Ownership should return object p
		assertEquals(b.getOwnership(),p);
	}

	/**
	 * Test method for {@link Piece#setY(int)}.
	 * @author Selman Selman
	 */
	public final void testSetY() {
		b.setY(1); // set y coordinate to 1
		//check that y is now 1
		assertEquals(b.getY(),1);
	}

	/**
	 * Test method for {@link Piece#getMoves()}.
	 * @author Selman Selman
	 */
	public final void testGetMoves() {
		b.possibleMoves(); //calculate possible moves of bishop at (0,0)
		ArrayList<Point> p = b.getMoves(); //get possible moves
		for(int i = 1; i <8; i++){
			assertTrue(p.contains(new Point(i,i))); //make sure possible moves are right
		}
		//makes sure it does not contain a wrong possible move
		assertFalse(p.contains(new Point(0,3)));
		
	}

	/**
	 * Test method for {@link Piece#move(int, int)}.
	 *@author Selman Selman
	 */
	public final void testMove() {
		//checks if bishop will move diagonally
		b.move(1,1);
		assertEquals(b.getX(),1);
		assertEquals(b.getY(), 1);
		//new x and y coordinates are 1 and 1 respectively 
		//check if bishop will not move vertically/horizontally
		b.move(1,2); // knight should not move
		assertEquals(b.getX(),1);
		assertEquals(b.getY(),1);
		
		b.move(2,1); //knight should not move
		assertEquals(b.getX(),1);
		assertEquals(b.getY(),1);
		//move knight out of boundaries
		b.move(9,9); //knight should not move
		assertEquals(b.getX(),1);
		assertEquals(b.getY(),1);
	}

}
